package lab02.test24;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;

public class Test24 {
    public static void main(String[] args) throws ParseException {
    //计算两个日期的天数之差
        SimpleDateFormat time=new SimpleDateFormat("yyyyMMdd");
        Scanner date =new Scanner(System.in);
        System.out.println("请输入两个日期yyyyMMdd，第二个日期大于第一个");
        String date1= date.next();
        String date2= date.next();

        Date time1=time.parse(date1);
        Date time2=time.parse(date2);

        Calendar c1=Calendar.getInstance();
        c1.setTime(time1);
        Calendar c2=Calendar.getInstance();
        c2.setTime(time2);

        int day1=c1.get(Calendar.DAY_OF_YEAR);
        System.out.println(String.valueOf(day1));
        int day2=c1.get(Calendar.DAY_OF_YEAR);
        System.out.println(String.valueOf(day2));

        int year1=c1.get(Calendar.YEAR);
        int year2=c2.get(Calendar.YEAR);
        if (year1!=year2){
            int dayBetween=0;
            for (int i=year1;i<year2;i++){
                if (i%4==0&&i%100!=0||i%400==0){
                    dayBetween+=366;
                }else{
                    dayBetween+=365;
                }
            }
            dayBetween+=(day2-day1);
            System.out.println(dayBetween);
        }else{
            System.out.println("判断day2-day1"+(day2-day1));
        }

    }
}
